package com.lutzyt.delivery.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lutzyt.delivery.bean.Area;
import com.lutzyt.delivery.mapper.AreaDAO;
import com.lutzyt.delivery.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class AreaServiceImpl extends ServiceImpl<AreaDAO, Area> implements AreaService {

  @Autowired
  private AreaDAO areaDAO;

  @Transactional(readOnly = true)
  @Override
  public Area findById(Integer id) {
    return areaDAO.selectById(id);
  }

  @Transactional(readOnly = true)
  @Override
  public IPage<Area> findByPage(int pageNum, int pageSize) {
    return areaDAO.selectPage(new Page<>(pageNum, pageSize), null);
  }

  @Override
  public void insert(Area area) {
    areaDAO.insert(area);
  }

  @Override
  public void update(Area area) {
    areaDAO.updateById(area);
  }

  @Override
  public void deleteById(Integer id) {
    areaDAO.deleteById(id);
  }

  @Override
  public Area findByCode(Integer code) {
    return this.lambdaQuery().eq(Area::getAreacode, code).one();
  }
}